package main

import "fmt"

var pc [256]byte

func init() {
	for i := range pc {
		pc[i] = pc[i/2] + byte(i&1)
	}
}

func PopCount(x int64) int {
	ret := pc[byte(x>>(0*8))] +
		pc[byte(x>>(1*8))] +
		pc[byte(x>>(2*8))] +
		pc[byte(x>>(3*8))] +
		pc[byte(x>>(4*8))] +
		pc[byte(x>>(5*8))] +
		pc[byte(x>>(6*8))] +
		pc[byte(x>>(7*8))] +
		pc[byte(x>>(8*8))]

	return int(ret)
}

func PopCountV2(x int64) int {
	ret := 0
	for x != 0 {
		if x&1 == 1 {
			ret += 1
		}
		x >>= 1
	}
	return ret
}

func PopCountV3(x int64) int {
	ret := 0
	for x != 0 {
		ret += 1
		x &= (x - 1)
	}

	return ret
}

func main() {
	fmt.Println(PopCount(15))
}
